<?php
# http://www.php.net/manual/en/function.date.php#101379

$holidays = array();
$holidays[] = strtotime('+1 day',easter_date()); 
$holidays[] = strtotime('1.1.'.date('Y'));
$holidays[] = strtotime('8.5.'.date('Y'));
$holidays[] = strtotime('5.7.'.date('Y'));
$holidays[] = strtotime('6.7.'.date('Y'));
$holidays[] = strtotime('28.9.'.date('Y'));
$holidays[] = strtotime('28.10.'.date('Y'));
$holidays[] = strtotime('17.11.'.date('Y'));
$holidays[] = strtotime('1.5.'.date('Y'));
$holidays[] = strtotime('24.12.'.date('Y'));
$holidays[] = strtotime('25.12.'.date('Y'));
$holidays[] = strtotime('26.12.'.date('Y'));

$holidays[] = strtotime('+1 year', strtotime('1.1.'.date('Y'))) ; // funguje to jen v ramci aktualniho roku, pridame aspon Novy rok roku nasledujiciho

function networkdays($s, $e) {
    global $holidays;
    // If the start and end dates are given in the wrong order, flip them.   
    if ($s > $e)
        return networkdays($e, $s);

    // Find the ISO-8601 day of the week for the two dates.
    $sd = date("N", $s);
    $ed = date("N", $e);

    // Find the number of weeks between the dates.
    $w = floor(($e - $s)/(86400*7));    # Divide the difference in the two times by seven days to get the number of weeks.
    if ($ed >= $sd) { $w--; }        # If the end date falls on the same day of the week or a later day of the week than the start date, subtract a week.

    // Calculate net working days.
    $nwd = max(6 - $sd, 0);    # If the start day is Saturday or Sunday, add zero, otherewise add six minus the weekday number.
    $nwd += min($ed, 5);    # If the end day is Saturday or Sunday, add five, otherwise add the weekday number.
    $nwd += $w * 5;        # Add five days for each week in between.

    // Iterate through the array of holidays. For each holiday between the start and end dates that isn't a Saturday or a Sunday, remove one day.
    foreach ($holidays as $h) {
        //$h = strtotime($h);
        //echo date("d.m.y ",$h);
        if ($h >= $s && $h <= $e && date("N", $h) < 6) // HB fixed a bug, missing = 
            $nwd--;
    }

    return $nwd;
}
//echo networkdays(strtotime("5.4.2012"),strtotime("10.4.2012"));

?>
